/*
 * @lc app=leetcode.cn id=766 lang=javascript
 *
 * [766] 托普利茨矩阵
 */

// @lc code=start
/**
 * @param {number[][]} matrix
 * @return {boolean}
 */
var isToeplitzMatrix = function (matrix) {
  let height = matrix.length;
  let width = matrix[0].length;
  for (let k = 0; k < width + height - 1; k++) {
    let val = undefined;
    let i = Math.max(0, 1 + k - width);
    let j = i + width - 1 - k;
    for (; i < height && j < width; i++, j = i + width - 1 - k) {
      if (val === undefined) {
        val = matrix[i][j];
      } else if (matrix[i][j] !== val) {
        return false
      }
    }
  }
  return true;
};
// @lc code=end
isToeplitzMatrix([[18], [66]])
